package thread;

public class SyncDemo4 {
    public static void main(String[] args) {
        Aoo a=new Aoo();
        Thread t1=new Thread(){
            public void run() {
                a.methodA();
            }
        };
        Thread t2=new Thread(){
            public void run() {
                a.methodB();
            }
        };

        t1.start();
        t2.start();
    }
}



class Aoo{
    public synchronized void methodA(){
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName() + ":正在执行A方法");
            Thread.sleep(5000);
            System.out.println(t.getName() + ":执行A完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void methodB(){
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName() + ":正在执行B方法");
            Thread.sleep(5000);
            System.out.println(t.getName() + ":执行B完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}